# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Testing
# RoleDef/Role and Dependencies
#              Proxy
#              /  |
#           Head  |            
#             \   |
#            Workers (2 of them)
#
# VMs
# VM0: Proxy+Head
# VM1: Worker1
# VM2: Worker2
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

from crv.model.crvmodel import *
from crv.tools import crvtools

def createSampleData(metadata,session):

    #Role Definitions
    rdProxy=RoleDef('Proxy',"Proxy Server","at3_proxy","puppet")
    rdNFS=RoleDef('NFS',"NFS Server","at3_nfs","puppet")
    rdHead=RoleDef('Head',"Condor Head","at3_head","puppet")
    rdWorker=RoleDef('Worker',"Condor Worker","at3_worker","puppet")
    
    rdNFS.dependOn.append(rdProxy)
    rdWorker.dependOn.append(rdNFS)    
    rdWorker.dependOn.append(rdHead)
    rdWorker.dependOn.append(rdProxy)
    rdHead.dependOn.append(rdNFS)
    rdHead.dependOn.append(rdProxy)

    #Roles - i.e. realized role definitions
    rProxy=Role('rProxy')
    rProxy.roleDef=rdProxy
    rProxy.enabled=True
    
    rNFS=Role('rNFS')
    rNFS.roleDef=rdNFS
    rNFS.enabled=True
    
    rHead=Role('rHead')
    rHead.roleDef=rdHead
    rHead.enabled=False

    rWorker1=Role('rWorker1')
    rWorker1.roleDef=rdWorker
    rWorker1.enabled=False
    
    rWorker2=Role('rWorker2')
    rWorker2.roleDef=rdWorker
    rWorker2.enabled=False
    
    crvtools.buildRoleDep([rProxy,rNFS,rHead,rWorker1,rWorker2])
    
    vm0=VM("VM0")
    vm0.vmtype="euca"
    rProxy.vm=vm0

    vm3=VM("VM3")
    vm3.vmtype="euca"
    rHead.vm=vm3
    
    vm4=VM("VM4")
    vm4.vmtype="euca"
    rNFS.vm=vm4
    
    vm1=VM("VM1")
    vm1.vmtype="euca"
    rWorker1.vm=vm1
    
    vm2=VM("VM2")
    vm2.vmtype="euca"
    rWorker2.vm=vm2

    vm0.clienttype="centos5_puppet"
    vm1.clienttype="centos5_puppet"
    vm2.clienttype="centos5_puppet"
    vm3.clienttype="centos5_puppet"        
    vm4.clienttype="centos5_puppet"        

    cl=Cluster("tier3")
    cl.role.append(rProxy)
    cl.role.append(rNFS)
    cl.role.append(rHead)
    cl.role.append(rWorker1)
    cl.role.append(rWorker2)    

    cl.targetSC=Cluster.SC.SC_STARTED
    
    session.add(cl)
    
